Skip to content

Latest commit

 

History

History
30 lines (25 loc) · 630 Bytes

README.md

File metadata and controls

30 lines (25 loc) · 630 Bytes

504. Base 7

Given an integer, return its base 7 string representation.

Example 1:

Input: 100 Output: "202" 

Example 2:

Input: -7 Output: "-10" 

Note: The input will be in range of [-1e7, 1e7].

Solutions (Python)

1. Solution

classSolution: defconvertToBase7(self, num: int) ->str: ifnum>=7: returnself.convertToBase7(num//7) +str(num%7) elifnum<0: return'-'+self.convertToBase7(-num) elifnum<7: returnstr(num)
close